<?php
class ext_penawaran_model extends MY_Model {
	var $nama_tabel = 'ext_penawaran';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	 a.id_penawaran_pk, a.id_pembeli_fk,a.id_status_penawaran_fk,a.ket_penawaran, TO_CHAR(a.tgl_penawaran,'DD/MM/YYYY') tgl_penawaran, b.nama_pembeli, c.nama_status_penawaran,
					TO_CHAR(a.tgl_jatuh_tempo,'DD/MM/YYYY') tgl_jatuh_tempo
					FROM	".$this->nama_tabel." a
					left join ext_pembeli b on a.id_pembeli_fk=b.id_pembeli_pk
					left join ext_status_penawaran c on a.id_status_penawaran_fk=c.id_status_penawaran_pk
					WHERE	(
							UPPER(id_penawaran_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(id_pembeli_fk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(ket_penawaran,'')) LIKE '%".strtoupper(post('keyword'))."%'
							)
					ORDER BY ".(post('sort')=='' ? 'id_penawaran_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		//echo $ls_sql;			
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_penawaran_pk' => $arr_rule['id_penawaran_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetSingleView($id_penawaran_pk) {
		$sql = "select id_penawaran_pk, id_pembeli_fk,id_status_penawaran_fk ,TO_CHAR(tgl_penawaran,'DD/MM/YYYY') tgl_penawaran, 
				TO_CHAR(tgl_jatuh_tempo,'DD/MM/YYYY') tgl_jatuh_tempo,ket_penawaran
				from ext_penawaran
				where id_penawaran_pk = '".strtoupper($id_penawaran_pk)."'
				";

		$result = $this->db->query($sql);


		if($result->num_rows() == 1) {
			return $result->row_array();
		} else {
			return NULL;
		}

	}

}
?>